<template>
    <div>
        <button @click="increment">增加计数</button>
        <p>计数: {{ obj.count }}</p>
    </div>
</template>

<script setup>
import { ref, watch } from 'vue';

const obj = ref({ count: 0 });

const increment = () => {
    obj.value.count++;
};

// 提供一个 getter 函数
watch(
    () => obj.value.count,
    (count, prevCount) => {
        console.log(`计数从 ${prevCount} 变为 ${count}`);
    }
);
</script>